﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace YJYpublicClass
{
    public partial class Frm_Welcome : Form
    {
        public Frm_Welcome()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 关闭窗体标识
        /// </summary>
        public bool CloseForm = false;

        private void Frm_Welcome_Load(object sender, EventArgs e)
        {
            this.Opacity = 0;        //初始化窗体为透明窗体
            timer_DispForm.Start();
        }

        /// <summary>
        /// 显示设置
        /// </summary>
        /// <param name="ProgressBar"></param>
        public void LoadingProgress(int ProgressBar)
        {
            try
            {
                if (ProgressBar > 100 || ProgressBar < 0)
                { MessageBox.Show("设置进度值超出范围!"); return; }

                bar_step.Value = ProgressBar;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        /// <summary>
        /// 显示设置
        /// </summary>
        /// <param name="ProgressBar"></param>
        /// <param name="LoadingMsg"></param>
        public void LoadingProgress(int ProgressBar, string LoadingMsg)
        {
            try
            {
                if (ProgressBar > 100 || ProgressBar < 0)
                { MessageBox.Show("设置进度值超出范围!"); return; }

                labLoadText.Text = LoadingMsg;
                bar_step.Value = ProgressBar;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        /// <summary>
        /// 显示设置
        /// </summary>
        /// <param name="ProgressBar"></param>
        /// <param name="LoadingMsg"></param>
        public void LoadingProgress(int ProgressBar, string LoadingMsg, int ThreadSleep)
        {
            try
            {
                if (ProgressBar > 100 || ProgressBar < 0)
                { MessageBox.Show("设置进度值超出范围!"); return; }

                labLoadText.Text = LoadingMsg;
                bar_step.Value = ProgressBar;
                Thread.Sleep(ThreadSleep);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void timer_DispForm_Tick(object sender, EventArgs e)
        {
            if (this.Opacity <= 1)
                this.Opacity += 0.33;

            if (CloseForm)
            {
                timer_DispForm.Stop();
                this.Close();
            }
        }
    }
}
